﻿<%@ Page Language="C#" %>

<%
    int count=(int)Session["Login_Failed"];
    if ( count< 3)
    {
        String userName = Request["userName"];
        String password = Request["password"];
        DTO.NguoiDungDto user = BUS.NguoiDungBus.LayNguoiDungTheoTen(userName);
        if (user == null)
        {
            Response.Write("0");
            count++;
            Session["Login_Failed"] = count;
        }
        else if (user.TrangThai == "active")
        {
            if (user.MatKhau != BUS.NguoiDungBus.EncodePassword(password))
            {
                count++;
                Session["Login_Failed"] = count;
                Response.Write("0");

            }
            else
            {
                Response.Write(user.LoaiNguoiDung);
                Session["user"] = user;
            }
        }
        else
        {
            Response.Write("-2");
                
        }
    }
    else
    {
        
        Response.Write("-1");  
    }
    
%>